home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************
- * *
- * Popup menu bars for inside dialog boxes and dropside menus *
- * *
- * Copyright (C) 1993 - 1994, Bitgate Software and Clever Bits. *
- * All Rights Reserved. *
- * *
- * Routines to handle dropdown menus (like Windows), popup menus *
- * with previously selected object alignment, side menu bars for *
- * popups, dropdowns, and desktop menu routines. *
- * *
- ********************************************************************
- * *
- * Update log: *
- * *
- * [1.6.93 - 19.2.94] Ken Hollis *
- * - designed routines *
- * PDoPopup - fixed serious bug in AES buffer grab *
- * - fixed drawing of objects for 3D type *
- * - fixed DISABLED bug and optimized stuff *
- * - added growth animation option *
- * PDoPopupAddr - added for OBJECTs already found *
- * - took out memory allocations (problems!) *
- * PPopup_DialXY - fixed repositioning problem *
- * - touched up routines *
- * PPopup_WinXY - fixed repositioning problem *
- * - majorly modified and optimized *
- * - touched up routines *
- * *
- * To be added: *
- * """""""""""" *
- * Keyboard movable selection bar *
- * Up and down arrows for additional choices (choices via an array)*
- * Popup menus act same as regular menu bars (ie. attach/detach) *
- * Popup menus can be windowed as well *
- * *
- ********************************************************************/
-
- #include <vdi.h> /* Standard VDI bindings */
- #include <tos.h> /* Standard TOS bindings */
-
- #include <stdio.h> /* Standard IO bindings */
-
- #include "winlib.h" /* WinLIB header file */
- #include "nkcc.h" /* Normalized Keycodes header file */
-
- void *dpbuffer, *dialbuffer, *winbuffer;
- int PopupVDIhandle;
- MFDB srcp,destp;
- long bufferp, buflenp;
-
- #ifndef __POPUP__
- #define __POPUP__
- #endif
-
- GLOBAL void PPopup_DialXY(OBJECT *srctree, int srcindex, OBJECT *desttree)
- {
- int tx, ty;
- int ox, oy;
-
- desttree->ob_x = srctree->ob_x;
- desttree->ob_y = srctree->ob_y;
-
- objc_offset(srctree, srcindex, &ox, &oy);
-
- desttree->ob_x += ox;
- desttree->ob_y += oy;
-
- desttree->ob_x--;
- desttree->ob_y--;
-
- if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
- tx = 0;
- else
- tx += 8;
-
- if (((desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
- ty = 0;
- else
- ty -= desttree->ob_y + desttree->ob_height;
-
- desttree->ob_x -= tx;
- desttree->ob_y += ty;
- }
-
- GLOBAL void PDropdown_DialXY(OBJECT *srctree, int srcindex, OBJECT *desttree)
- {
- int tx, ty;
- int ox, oy;
-
- desttree->ob_x = srctree->ob_x;
- desttree->ob_y = srctree->ob_y + srctree->ob_height;
-
- objc_offset(srctree, srcindex, &ox, &oy);
-
- desttree->ob_x += ox;
- desttree->ob_y += oy;
-
- desttree->ob_x--;
- desttree->ob_y -= 2;
-
- if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
- tx = 0;
- else
- tx += 8;
-
- if (((desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
- ty = 0;
- else
- ty -= desttree->ob_y + desttree->ob_height;
-
- desttree->ob_x -= tx;
- desttree->ob_y += ty;
- }
-
- GLOBAL void PPopup_WinXY(WINDOW *win, int srcindex, OBJECT *desttree)
- {
- int tx, ty;
- GRECT work;
-
- WWindGet(win, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h);
-
- desttree->ob_x = win->tree[srcindex].ob_x + work.g_x;
- desttree->ob_y = win->tree[srcindex].ob_y + work.g_y;
-
- desttree->ob_x--;
- desttree->ob_y--;
-
- if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
- tx = 0;
-
- if ((ty = (desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
- ty = 0;
-
- desttree->ob_x -= tx;
- desttree->ob_y -= ty;
- }
-
- GLOBAL void PDropdown_WinXY(WINDOW *win, int srcindex, OBJECT *desttree)
- {
- int tx, ty;
- GRECT work;
-
- WWindGet(win, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h);
-
- desttree->ob_x = win->tree[srcindex].ob_x + work.g_x;
- desttree->ob_y = (win->tree[srcindex].ob_y + win->tree[srcindex].ob_height) + work.g_y;
-
- desttree->ob_x--;
- desttree->ob_y -= 2;
-
- if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
- tx = 0;
-
- if ((ty = (desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
- ty = 0;
-
- desttree->ob_x -= tx;
- desttree->ob_y -= ty;
- }
-
- GLOBAL void PMovePopupCoord(OBJECT *desttree, int x, int y)
- {
- int tx, ty;
-
- desttree->ob_x = x;
- desttree->ob_y = y;
-
- desttree->ob_x--;
- desttree->ob_y--;
-
- if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
- tx = 0;
-
- if ((ty = (desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
- ty = 0;
-
- desttree->ob_x -= tx;
- desttree->ob_y -= ty;
- }
-
- GLOBAL void PMovePopup(OBJECT *dial, int oldpos, int newpos)
- {
- OBJECT *ob,*obnewpos;
- int obx,oby,obnx,obny;
-
- ob = &dial[ROOT];
- rsrc_gaddr(R_TREE, oldpos, &ob);
- obnewpos = &dial[newpos];
- rsrc_gaddr(R_OBJECT, newpos, &obnewpos);
- objc_offset(ob, oldpos, &obx, &oby);
-
- obnx = (obnewpos->ob_x) - obx;
- obny = (obnewpos->ob_y) - (oby - 1);
- ob->ob_x = obnx;
- ob->ob_y = obny;
-
- if (ob->ob_x + ob->ob_width > desk.g_x + desk.g_w)
- ob->ob_x = desk.g_x + desk.g_w - ob->ob_width;
- if (ob->ob_y + ob->ob_height > desk.g_y + desk.g_h)
- ob->ob_y = desk.g_y + desk.g_h - ob->ob_height;
- }
-
- /*
- * Move popup box relative to window
- *
- * win : Window structure
- * pindex : Popup index number
- * desttree: Destination tree (popup address)
- */
- GLOBAL void PMovePopup_WinXY(WINDOW *win, int pindex, OBJECT *desttree)
- {
- int tx, ty;
- int ox, oy;
- GRECT work;
-
- if (win->popups[pindex]<=0) return;
-
- WWindGet(win, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h);
-
- objc_offset(desttree, win->popups[pindex], &ox, &oy);
-
- desttree->ob_x = desttree->ob_x;
- desttree->ob_y = (desttree->ob_y - oy) + work.g_y;
-
- if (win->menubar!=NULL)
- desttree->ob_y += 17;
-
- if ((tx = (desttree->ob_x + desttree->ob_width) - (desk.g_x + desk.g_w)) < 0)
- tx = 0;
-
- if ((ty = (desttree->ob_y + desttree->ob_height) - (desk.g_y + desk.g_h)) < 0)
- ty = 0;
-
- desttree->ob_x -= tx;
- desttree->ob_y -= ty;
- }
-
- GLOBAL int PDoPopup(WINDOW *win, int index, OBJECT *menu_addr, int show, int x, int y, int w, int h)
- {
- int LastOb,CurrOb,work_out[57];
- int button,mx,my;
- void *ourbuffer;
- OBJECT *ptr;
- GRECT work;
-
- WWindGet(win, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h);
-
- vq_extnd(VDIhandle, 1, work_out);
-
- rsrc_gaddr(R_TREE, index, &ptr);
-
- ourbuffer = scrsave(VDIhandle, ptr->ob_x, ptr->ob_y, ptr->ob_width, ptr->ob_height);
-
- if (x!=0 && y!=0 && w!=0 && h!=0)
- graf_growbox(x + work.g_x, y + work.g_y, w, h, ptr->ob_x, ptr->ob_y, ptr->ob_width, ptr->ob_height);
-
- objc_draw(ptr, 0, 6, ptr->ob_x, ptr->ob_y, ptr->ob_width, ptr->ob_height);
- LastOb = -1;
-
- do {
- vq_mouse(VDIhandle,&button,&mx,&my);
- CurrOb = objc_find(ptr, 0, MAX_DEPTH, mx, my);
- if ((CurrOb==-1) && (ptr[LastOb].ob_flags & SELECTABLE) && !(ptr[LastOb].ob_state & DISABLED)) {
- objc_change(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- LastOb = -1;
- }
- if ((CurrOb>0) && (LastOb!=CurrOb) && (ptr[LastOb].ob_flags & SELECTABLE) && !(ptr[LastOb].ob_state & DISABLED)) {
- if ((LastOb>0) && !(ptr[LastOb].ob_state & DISABLED)) {
- objc_change(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
- LastOb = -1;
- }
- if ((CurrOb!=LastOb) && (ptr[CurrOb].ob_flags & SELECTABLE) && !(ptr[CurrOb].ob_state & DISABLED)) {
- if ((LastOb>0) && !(ptr[LastOb].ob_state & DISABLED)) {
- objc_change(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
- if ((CurrOb>0) && !(ptr[CurrOb].ob_state & DISABLED)) {
- objc_change(ptr,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,SELECTED,1);
- objc_draw(ptr,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
- LastOb = CurrOb;
- }
- } while(button!=1);
-
- if ((LastOb>0) && !(ptr[LastOb].ob_state & DISABLED) && (ptr[LastOb].ob_flags & SELECTABLE)) {
- objc_change(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(ptr,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
- if ((CurrOb>0) && !(ptr[CurrOb].ob_state & DISABLED) && (ptr[CurrOb].ob_flags & SELECTABLE)) {
- objc_change(ptr,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(ptr,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
-
- scrrestore(ourbuffer);
-
- if (x!=0 && y!=0 && w!=0 && h!=0)
- graf_shrinkbox(x + work.g_x, y + work.g_y, w, h, ptr->ob_x, ptr->ob_y, ptr->ob_width, ptr->ob_height);
-
- return(LastOb);
- }
-
- GLOBAL int PDoPopupAddr(OBJECT *index)
- {
- int LastOb,CurrOb,work_out[57];
- int button,mx,my;
- void *ourbuffer;
-
- vq_extnd(VDIhandle, 1, work_out);
-
- ourbuffer = scrsave(VDIhandle, index->ob_x, index->ob_y, index->ob_width, index->ob_height);
- objc_draw(index, 0, 6, index->ob_x, index->ob_y, index->ob_width, index->ob_height);
- LastOb = -1;
-
- do {
- vq_mouse(VDIhandle,&button,&mx,&my);
- CurrOb = objc_find(index, 0, MAX_DEPTH, mx, my);
- if ((CurrOb==-1) && (LastOb!=-1) && (index[LastOb].ob_flags & SELECTABLE) && !(index[LastOb].ob_state & DISABLED)) {
- objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- LastOb = -1;
- }
- if ((CurrOb>0) && (LastOb!=CurrOb) && (index[LastOb].ob_flags & SELECTABLE) && !(index[LastOb].ob_state & DISABLED)) {
- if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED)) {
- objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- }
- LastOb = -1;
- }
- if ((CurrOb!=LastOb) && (index[CurrOb].ob_flags & SELECTABLE) && !(index[CurrOb].ob_state & DISABLED)) {
- if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED)) {
- objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- }
- if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED)) {
- objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,SELECTED,1);
- }
- LastOb = CurrOb;
- }
- } while(button!=1);
-
- if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED) && (index[LastOb].ob_flags & SELECTABLE)) {
- objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
- if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED) && (index[CurrOb].ob_flags & SELECTABLE)) {
- objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
-
- scrrestore(ourbuffer);
-
- return(LastOb);
- }
-
- GLOBAL int POpenPopupWorkspace(void)
- {
- int WorkOut[64];
- int WorkIn[]={1,1,1,1,1,1,1,1,1,1,2};
- int j;
-
- PopupVDIhandle=graf_handle(&j,&j,&j,&j);
- v_opnvwk(WorkIn,&PopupVDIhandle,WorkOut);
-
- return(TRUE);
- }
-
- GLOBAL int PShowPopupDesk(OBJECT *index)
- {
- dpbuffer = scrsave(VDIhandle, index->ob_x, index->ob_y, index->ob_width, index->ob_height);
- if (dpbuffer) {
- objc_draw(index, 0, 6, index->ob_x, index->ob_y, index->ob_width, index->ob_height);
- return TRUE;
- } else
- return FALSE;
- }
-
- GLOBAL int PEndPopupDesk(OBJECT *index)
- {
- if (dpbuffer) {
- scrrestore(dpbuffer);
- return TRUE;
- } else {
- form_dial(3, index->ob_x, index->ob_y, index->ob_width, index->ob_height,
- index->ob_x, index->ob_y, index->ob_width, index->ob_height);
- return FALSE;
- }
- }
-
- GLOBAL int PDoPopupDeskMenu(OBJECT *index, int *retbtn)
- {
- int LastOb,CurrOb;
- int button,mx,my;
-
- *retbtn = 0;
- LastOb = -1;
-
- do {
- vq_mouse(VDIhandle,&button,&mx,&my);
- CurrOb = objc_find(index, 0, MAX_DEPTH, mx, my);
-
- if (CurrOb==-1) {
- if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED) && (index[LastOb].ob_flags & SELECTABLE)) {
- objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
- if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED) && (index[CurrOb].ob_flags & SELECTABLE)) {
- objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
-
- *retbtn = FALSE;
- return 0;
- }
-
- if ((CurrOb==-1) && (index[LastOb].ob_flags & SELECTABLE) && !(index[LastOb].ob_state & DISABLED)) {
- objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- LastOb = -1;
- }
- if ((CurrOb>0) && (LastOb!=CurrOb) && (index[LastOb].ob_flags & SELECTABLE) && !(index[LastOb].ob_state & DISABLED)) {
- if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED)) {
- objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- }
- LastOb = -1;
- }
- if ((CurrOb!=LastOb) && (index[CurrOb].ob_flags & SELECTABLE) && !(index[CurrOb].ob_state & DISABLED)) {
- if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED)) {
- objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- }
- if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED)) {
- objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,SELECTED,1);
- }
- LastOb = CurrOb;
- }
- } while(button!=1);
-
- if ((LastOb>0) && !(index[LastOb].ob_state & DISABLED) && (index[LastOb].ob_flags & SELECTABLE)) {
- objc_change(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(index,LastOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
- if ((CurrOb>0) && !(index[CurrOb].ob_state & DISABLED) && (index[CurrOb].ob_flags & SELECTABLE)) {
- objc_change(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h,NORMAL,1);
- objc_draw(index,CurrOb,0,desk.g_x,desk.g_y,desk.g_w,desk.g_h);
- }
-
- *retbtn = TRUE;
- return(LastOb);
- }